package Datastruct.Hufffman;


//哈夫曼树
public class Node implements Comparable<Node> {

    public int value;
    public Node left;
    public Node right;

    public Node(int value) {
        this.value = value;
    }

    /**
     * 比较大小
     *
     * @param o
     * @return int
     * this.value  -  node.value
     * <p>
     * -1 0 1
     */
    @Override
    public int compareTo(Node node) {


        return this.value - node.value;
    }

    //前序遍历
    public void preOrder() {
        System.out.println(this);
        if (this.left != null) {
            this.left.preOrder();
        }
        if (this.right != null) {
            this.right.preOrder();
        }
    }

    //中序遍历

    public void inOrder() {
        if (this.left != null) {
            this.left.inOrder();
        }
        System.out.println(this);

        if (this.right != null) {
            this.right.inOrder();
        }
    }

    //后序遍历
    public void postOrder() {
        if (this.left != null) {
            this.left.postOrder();
        }
        if (this.right != null) {
            this.right.postOrder();

        }
        System.out.println(this);
    }

    //打印权值
    @Override
    public String toString() {
        return "Node{" +
                "value=" + value +
                '}';
    }
}
